﻿//3.初始化入口
    $(function() {
        regUpload();
        loadfile();     
    });
    
   function loadfile(){
			$('#filegrid').datagrid({
				width:700,
				height:350,
				fit: true,
				nowrap: false,
				url:'../Controller.aspx?controller=LoadExeclController&method=loadFileData',
				striped: true,
				collapsible:true,
				rownumbers:true,	
				sortName: 'DocMuid',
				sortOrder: 'desc',
				remoteSort: false,
				loadMsg:'正在加载数据...',
				idField:'DocMuid',
				fitColumns: true,
			    pagination:true,
				columns:[[
			        {field:'DocName',title:'文件名',width:80},
					{field:'DocLength',title:'文件大小(KB)',width:20},
					{field:'UploadDate',title:'上传日期',width:100},
					{field:'DocPath',title:'文件路径',width:100}
				]],	
				singleSelect:true	
			});
			 $('#filegrid').datagrid('hideColumn','DocPath');
		}
    function regUpload(){
            $("#uploadify").uploadify({
            swf: '../../../../WebPlugin/jquery-easyui/uploadify/uploadify.swf',//上传的Flash，不用管，路径对就行
            uploader:'../Controller.aspx?controller=LoadExeclController&method=UploadFile',//Post文件到指定的处理文件
            folder:  '../../../../WebPlugin/jquery-easyui/uploadify/UploadFiles',
            auto : true,
            buttonText: '上传',//浏览按钮的Text
            fileTypeDesc: '*.xls|*.xlsx',//需过滤文件类型
		    fileTypeExts:'*.*',//需过滤文件类型的提示
		    multi: true,//是否允许多文件上传
		    uploadLimit: 999,//同时上传多小个文件
		    queueSizeLimit: 999,//队列允许的文件总数
		    removeCompleted : false,//当上传成功后是否将该Item删除
			onSelect: function(file){},//选择文件时触发事件
			onSelectError: function(file,errorCode,errorMsg){},//选择文件有误触发事件
			onUploadComplete: function(file){},//上传成功触发事件
			onUploadError: function(file,errorCode,errorMsg){},//上传失败触发事件
			onUploadProgress: function(file,fileBytesLoaded,fileTotalBytes){},//上传中触发事件
			onUploadStart: function(file){},//上传开始触发事件
            onUploadSuccess: function(event, response, status){AddDocItem();}  //当单个文件上传成功后激发的事件
            });
        }
    function AddDocItem()
    {
        $('#filegrid').datagrid('reload');
    }
    function DeleteDocument()
    {
        var r=confirm("您确定要删除该文件吗？")
        if (r==true)
        {
          var urlpath='../Controller.aspx?controller=LoadExeclController&method=DeleteDocument';
          var selected = $('#filegrid').datagrid('getSelected');
          if(selected==null)
          {
            alert('请选择要删除的文件！');
            return;
          }
          var data={docpath:selected.DocPath};
          requestAjax(urlpath,data,function(){ AddDocItem();});
        }
    }

   function ExcelToSql()
    {
        var r=confirm("您确定要将该文件导入到数据库吗？")
        if (r==true)
        {
          var urlpath='../Controller.aspx?controller=LoadExeclController&method=ExcelToSql';
          var selected = $('#filegrid').datagrid('getSelected');
          if(selected==null)
          {
            alert('请选择要导入的文件！');
            return;
          }
           $.messager.progress({
            title: '导入数据库',
            msg: '正在操作中请等待...'
          });
          var data={docpath:selected.DocPath};
          requestAjax(urlpath,data,function(){ $.messager.progress('close'); AddDocItem();}, function() { $.messager.progress('close');});
        }
    }